package com.hao.tool.web.module.computer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hao.tool.web.module.computer.dto.ComputerDTO;
import com.hao.tool.web.module.computer.entity.ComputerInfo;
import com.hao.tool.web.module.computer.mapper.ComputerMapper;
import com.hao.tool.web.module.computer.service.ComputerService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * description
 *
 * @author RuiHaoZ on GZ.cmhk
 * @date 2019-11-21 21:45
 */
@Service
public class ComputerServiceImpl extends ServiceImpl<ComputerMapper, ComputerInfo> implements ComputerService {

    @Override
    public ComputerInfo save(ComputerDTO dto, String userName) {
        ComputerInfo info = new ComputerInfo();

        info.setId(null)
                .setIp(dto.getIp())
                .setUsername(dto.getUsername())
                .setPassword(dto.getPassword())
                .setAppGroup(dto.getAppGroup())
                .setCreateTime(LocalDateTime.now())
                .setContent(dto.getContent())
                .setHeartTime(dto.getHeartTime())
                .setSystemType(dto.getSystemType())
                .setCreateUser(userName)
                .setComName(dto.getComName())
                .setTagGroup(dto.getTagGroup())
                .setAgentUser(dto.getAgentUser())
                .setLocation(dto.getLocation())
                .setDepartment(dto.getDepartment())
        ;
        this.save(info);
        return info;
    }


    @Override
    public List<ComputerInfo> getByUser(String userName) {
        QueryWrapper<ComputerInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("AGENT_USER", userName)
                .or().eq("CREATE_USER", userName);
        return list(wrapper);
    }
}
